package com.thrift.client.service.impl;

import com.thrift.client.annotation.ThriftClient;
import com.thrift.client.rpc.thriftcode.Student;
import com.thrift.client.rpc.thriftcode.StudentService;
import com.thrift.client.service.RpcStudentService;
import org.apache.thrift.TException;
import org.springframework.stereotype.Service;

/**
 * @author 何锦涛--CodeSleep
 * @since 2022/9/4 15:25
 */
@Service
public class RpcStudentServiceImpl implements RpcStudentService {

    @ThriftClient(serviceName = "Thrift-Server")
    public StudentService.Client client;

    @Override
    public Student getStudentByName(String name) throws TException {
        System.out.println("客户端请求用户名为:" + name + "的数据");
        Student studentByName = client.getStudentByName(name);
        System.out.println("获取成功！！！服务端返回的对象:" + studentByName);
        return studentByName;
    }

    @Override
    public void saveStudent(Student student) throws TException {
        System.out.println("客户端请求保存对象:" + student);
        client.saveStudent(student);
        System.out.println("保存成功！！！");
    }
}
